home *** CD-ROM | disk | FTP | other *** search
- /* XView.h
- *
- * This is the declaration of the View object, and the junk that
- * surrounds the view object.
- *
- * The view object is the basic 'widget' or 'subview' that makes
- * up the user interface for my application. It is basically implemented
- * as a small subset of the drawing view
- */
-
- /* YAAF - Yet another application framework
- * Copyright (C) 1997 William Edward Woody and In Phase Consulting
- *
- * This library is free software; you can redistribute it
- * and/or modify it under the terms of the GNU Library
- * General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or any
- * later version.
- *
- * This library is distributed in the hope that it will be
- * useful, but WITHOUT ANY WARRANTY; without even the implied
- * warranty of MERCHANTABIILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU Library General Public License for
- * more details.
- *
- * You should have received a copy of the GNU Library General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * To contact the author, either e-mail me at
- * woody@alumni.caltech.edu, or write to us at
- *
- * William Edward Woody
- * In Phase Consulting
- * 1545 Ard Eevin Avenue
- * Glendale, CA 91202
- */
-
- #ifndef __XVIEW_H__
- #define __XVIEW_H__
-
- #include <XConfig.h>
- #include <XEvent.h>
-
- #if OPT_MACOS == 1
- #include <QDOffscreen.h>
- #endif
-
- #if defined(__MWERKS__)
- #if defined(macintosh)
- #pragma options align=power
- #endif
- #if defined(__INTEL__)
- #pragma pack(push,2)
- #endif
- #endif
-
- /************************************************************************/
- /* */
- /* Forwards */
- /* */
- /************************************************************************/
-
- class XGDraw;
- class XGWindow;
- class XGWinManager;
- class XGDocument;
- class XGView;
- class XGPrinter;
-
- /************************************************************************/
- /* */
- /* Constructor Resource Records */
- /* */
- /************************************************************************/
-
- /* XGSViewResHeader
- *
- * This is the view resource header object; this is the preamble
- * which goes in front of the custom resource data to indicate the
- * offsets to the imbedded views
- */
-
- struct XGSViewResHeader {
- long mysize; /* My size */
- long offchild; /* Byte offset to first */
- long offsibling; /* Byte offset to sib */
- long fViewType; /* Required first field */
- };
-
- /************************************************************************/
- /* */
- /* View Factory */
- /* */
- /************************************************************************/
-
- /* XGArgStream
- *
- * This is the class which is used to stream the arguments for the
- * view factory. This class defines a simple object which is basically
- * a series of arguments--it is important that the arguments be pulled
- * in the correct order, from the first to the last.
- */
-
- class XGArgStream {
- public:
- XGArgStream(void *resData);
- virtual ~XGArgStream();
-
- /*
- * Argument accessor functions
- */
-
- bool GetBoolean();
- long GetInteger();
- void GetString(short, char *);
-
- protected:
- void GetArg(short,void *);
-
- private:
- void *fResData;
- };
-
- /* XGViewFactory
- *
- * This is the factory abstract type. If you want to automatically
- * create views from a resource file, you need to specify the factory
- * class to construct the specified view as a subclass of this.
- */
-
- class XGViewFactory {
- public:
- XGViewFactory();
- virtual ~XGViewFactory();
-
- /*
- * The function to override to create my thing
- */
-
- virtual XGView *CreateView(long viewID, XGView *parent, XGArgStream &) = 0;
-
- /*
- * Global (and internal) accessor
- */
-
- static XGView *_Create(long,XGView *,XGSViewResHeader *);
- static XGView *_Create(XGView *,short);
- private:
- XGViewFactory *fNext;
- static XGViewFactory *gList;
- };
-
- /************************************************************************/
- /* */
- /* Draw Management */
- /* */
- /************************************************************************/
-
- /* XGDraw
- *
- * This is the draw class object which forces the focus to the
- * specified view, sets things up, and sets a drawing global.
- *
- * It is presumed that this drawing operation is an atomic
- * operation; that is, while drawing happens, no other objects can
- * draw in another task. That's done by using an internal mutex
- * object associated with the task ID; that is, serial operations
- * on the display is kept by preventing a second task to succeed
- * in calling the XGDraw constructor when a first task is operating.
- *
- * As on some architectures the draw flush is associated with
- * the destructor of this object, it's probably not a good idea to
- * keep one of these around. That is, this should be created as
- * an automatic object.
- */
-
- class XGDraw {
- public:
- XGDraw(XGView *v, bool lc = true);
- XGDraw(XGPrinter *v);
- virtual ~XGDraw();
-
- /*
- * Additional state support
- */
-
- static XGDraw *GetDraw()
- {
- return gDraw;
- }
-
- /*
- * Clipping Support
- */
-
- void ClipRect(Rect *r = NULL);
-
- #if OPT_WINOS == 1
- /*
- * Windows support--This works as a global, as my serialized
- * access means that only one drawing context can be the current
- * drawing context.
- */
-
- HDC GetDC() const
- {
- return fDC;
- }
- #endif
-
- private:
- void CreateContext(bool);
- void SaveContext();
- void RestoreContext();
- void DestroyContext();
-
- /*
- * Internal globals
- */
-
- static XGDraw *gDraw; // Draw stack
- XGDraw *fLast;
- XGView *fView;
- XGPrinter *fPrint;
-
- /*
- * Internal state information
- */
-
- #if OPT_MACOS == 1
- PenState fPenState;
- short fFont;
- short fFace;
- short fSize;
- short fMode;
- RGBColor fForeColor;
- RGBColor fBackColor;
- Fixed fSpExtra;
-
- RgnHandle fClip;
- Point fOffset;
- GrafPtr fPort;
- #endif
-
- #if OPT_WINOS == 1
- HDC fDC;
- long fDCSave;
- #endif
- };
-
-
- /************************************************************************/
- /* */
- /* View Definition */
- /* */
- /************************************************************************/
-
- /* XGSViewInitRecord
- *
- * This is the initialization record for creating one of these
- * if it's programmatically built
- */
-
- struct XGSViewInitRecord {
- /*
- * View specification
- */
-
- long fViewType;
-
- short fViewID;
- long fRefNum;
-
- bool fLockLeft;
- bool fLockTop;
- bool fLockRight;
- bool fLockBottom;
-
- short fAutoLeft;
- short fAutoTop;
- short fAutoRight;
- short fAutoBottom;
-
- bool fVisible;
- bool fEnabled;
- bool fTabStop;
- };
-
- /* XGView [type 'VIEW']
- *
- * This is the base class for defining a view object. This is the root
- * of all of my drawing handling and processing.
- *
- * This is the workhorse class; this class handles encapsulating
- * the drawing subviews that I can draw into. How this is handled differs
- * between the Macintosh and Windows; the essence of this, however, is
- * that this class only specifies the boundary of the view--the
- * drawing is mediated by the XGDraw code.
- *
- * On the Macintosh, the XGView only contains the geometry of the
- * area that this view covers. The XGDraw object then converts this
- * geometry into a drawing area that we can draw into.
- *
- * On Windows, the XGView also contains the geometry of the HWND
- * child object this view contains--the XGDraw object simply opens the
- * HDC for this thing.
- *
- * The essence of it, however, is that the drawing is all handled
- * by the XGDraw code; this manages the geometry.
- */
-
- class XGView : public XGDispatch {
- public:
- /*
- * Construction/Destruction
- */
-
- XGView(long); // Special-for windows
- XGView(XGArgStream &); // Special-for windows
- XGView(XGView *parent, XGArgStream &init, bool nowin = false);
- XGView(XGView *parent, XGSViewInitRecord &init, bool nowin = false);
- virtual ~XGView();
-
- /*
- * Public event messages. Override these to handle this
- * view's behaviour.
- */
-
- virtual void DoDrawView(Rect);
- virtual void DoActivate(bool);
-
- virtual bool DoMouseDown(Point,short);
- virtual void DoMouseMove(Point,short);
- virtual void DoMouseUp(Point,short);
-
- virtual void DoSizeView(void);
- virtual void DoMoveView(void);
-
- /*
- * Focus support
- */
-
- virtual XGDispatch *SetFocus();
-
- /*
- * View display processing
- */
-
- bool IsVisible() const { return fVisible; }
- virtual void ShowView();
- virtual void HideView();
-
- bool IsEnabled() const { return fEnabled; }
- virtual void EnableView();
- virtual void DisableView();
-
- bool IsActive() const;
- bool IsCapture() const;
- bool IsTabStop() const { return fTabStop; }
-
- long GetRefNum() const { return fRefNum; }
- void SetRefNum(long x) { fRefNum = x; }
-
- long GetViewType() const { return fViewType; }
- short GetViewID() const { return fViewID; }
-
- /*
- * View hierarchy
- */
-
- XGView *GetParent() const { return fParent; }
- XGView *GetChild() const { return fChild; }
- XGView *GetSibling() const { return fSibling; }
- XGWindow *GetWindow() const { return fRoot; }
- XGDocument *GetDocument() const;
-
- XGView *FindViewByID(short);
- XGView *FindViewByPoint(Point);
-
- /*
- * View scrolling. This exists independant of the drawing
- * object XGDraw, in order to handle scrolling a scrollbar
- */
-
- virtual void Scroll(long,long);
- void ScrollView(long,long,Rect *r = NULL);
-
- /*
- * View location and view manipulation
- */
-
- Point GetPos() const { return fPos; }
- Point GetSize() const { return fSize; }
- virtual Rect GetContentRect() const;
-
- void SetLocation(Rect);
- void AutoLocate(Rect);
-
- void GlobalToView(Point *p) const
- {
- p->h -= fGlobalPos.h;
- p->v -= fGlobalPos.v;
- }
- void GlobalToView(Rect *r) const
- {
- r->left -= fGlobalPos.h;
- r->top -= fGlobalPos.v;
- r->right -= fGlobalPos.h;
- r->bottom -= fGlobalPos.v;
- }
- void ViewToGlobal(Point *p) const
- {
- p->h += fGlobalPos.h;
- p->v += fGlobalPos.v;
- }
- void ViewToGlobal(Rect *r) const
- {
- r->left += fGlobalPos.h;
- r->top += fGlobalPos.v;
- r->right += fGlobalPos.h;
- r->bottom += fGlobalPos.v;
- }
-
- /*
- * Drawing Support routines
- */
-
- void InvalView(Rect *r = NULL);
- void ValidView(Rect *r = NULL);
- void UpdateView();
-
- /*
- * Internal support routines
- */
-
- Rect _GetClipRect() const { return fGlobalRect; }
-
- #if OPT_WINOS == 1
- HWND _CreateHWND(Rect);
- HWND _GetHWND() const { return fViewHWND; }
- void _SetHWND(HWND w) { fViewHWND = w; }
- static XGView *_GetXGView(HWND w);
- #endif
-
- #if OPT_MACOS == 1
- void _DrawViewHierarchy(Rect ginval);
- void _ActivateViewHierarchy(bool);
-
- /*
- * Magic support
- */
-
- void _PushDC();
- void _PopDC();
- Rect _CalcInval();
- #endif
-
- protected:
- void ClearTabStop()
- {
- fTabStop = false;
- }
-
- private:
- /*
- * Initialization support
- */
-
- void IInitView(XGView *parent, XGSViewInitRecord &, bool);
-
- /*
- * Resize support
- */
-
- void CalcPos(void);
- Rect CalcAutoLocate(Rect);
-
- /*
- * Basic hierarchy relationship pointers
- */
-
- XGWindow *fRoot;
- XGView *fChild;
- XGView *fSibling;
- XGView *fParent;
-
- /*
- * Personal status
- */
-
- bool fVisible;
- bool fEnabled;
- bool fTabStop;
- bool fReserved;
-
- /*
- * View specification
- */
-
- long fViewType;
- short fViewID;
- long fRefNum;
- #if OPT_WINOS == 1
- HWND fViewHWND;
- #endif
-
- /*
- * View location
- */
-
- Point fSize; // Current size of me
- Point fPos; // Current pos in parent
- Point fGlobalPos; // Global pos in window
- Rect fGlobalRect; // Clipped view rectangle
-
- /*
- * Auto resize structures
- */
-
- bool fLockLeft;
- bool fLockTop;
- bool fLockRight;
- bool fLockBottom;
-
- short fAutoLeft;
- short fAutoTop;
- short fAutoRight;
- short fAutoBottom;
-
- friend class XGWindow;
- friend class XGDraw;
-
- #if OPT_WINOS == 1
- friend LRESULT CALLBACK _GSingleWindowProc(HWND w, UINT msg, WPARAM wp, LPARAM lp);
- friend LRESULT CALLBACK _GViewWindowProc(HWND w, UINT msg, WPARAM wp, LPARAM lp);
- #endif
- };
-
- #if defined(__MWERKS__)
- #if defined(macintosh)
- #pragma options align=reset
- #endif
- #if defined(__INTEL__)
- #pragma pack(pop)
- #endif
- #endif
-
-
- #endif // __XVIEW_H__
-